/**
 * 用于展示重复录入的简历
 */
import { history } from 'umi'
import React from 'react';
import { Table, Button } from 'antd';
import style from './style.less';
import { CANDIDATE_STATUS } from '../../dictionary';

/**
 * 用于展示重复录入的简历
 */
const DuplicateResumeList = ({ closeModal, duplicateArr = [] }) => {
    /**
     * 点击查看详情
     */
    const handleDetailBtnClick = record => {
        console.log(record);
        console.log(closeModal);
        let activeKey = 'RESUME'; // 控制目标页面中的tab,默认状态去简历页面 INTERVIEW面试,RESUME简历信息,HIRE录用
        if (record.resumeStep === 3) {
            activeKey = 'INTERVIEW'; // 「面试」阶段所有状态，打开简历详情定位至「面试」页签
        } else if (record.resumeStep === 4) {
            activeKey = 'HIRE'; // 「录用」阶段所有状态，打开简历详情定位至「录用」页签
        } else if (
            // 「候选-待接受」状态，打开简历详情定位至「面试」页签
            record.resumeStep === 2 &&
            record.resumeStatus === CANDIDATE_STATUS[2].value
        ) {
            activeKey = 'INTERVIEW';
        }
        history.push({
            pathname: '/office/personnelManagement/recruitment/resume/detail',
            query: { id: record.resumeId, activeKey }
        });
        // closeModal();
    };

    /**
     *  返回录用阶段名称
     */
    const renderStageName = resumeStep => {
        const stageArr = ['', '简历', '候选', '面试', '录用', '入职'];
        return <span>{stageArr[resumeStep]}</span>;
    };

    const columns = [
        {
            title: '招聘需求',
            dataIndex: 'dutyName',
            width: 178
        },
        {
            title: '招聘负责人',
            dataIndex: 'principalEmployeeName',
            width: 100
        },
        {
            title: '阶段',
            resumeStep: 'resumeStep',
            width: 80,
            render: (text, record) => renderStageName(record.resumeStep)
        },
        {
            title: '状态',
            dataIndex: 'resumeStatusName',
            width: 90
        },
        {
            title: '操作',
            dataIndex: 'operation',
            width: 100,
            render: (text, record) => {
                if (record.dataScope) {
                    // 有数据权限才查看详情
                    return (
                        <Button
                            onClick={() => {
                                handleDetailBtnClick(record);
                            }}
                            style={{ color: '#5590F6', padding: '0px' }}
                            type="link"
                        >
                            查看详情
                        </Button>
                    );
                }
                return null;
            }
        }
    ];
    return (
        <Table
            className={style.smallRow}
            columns={columns}
            rowKey="resumeId"
            dataSource={duplicateArr}
            pagination={false}
            scroll={{ y: duplicateArr.length > 4 ? 190 : 0 }}
        />
    );
};

export default DuplicateResumeList;
